﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace NusyaTester {
    enum TestType {
        VARIANTS,
        MISS_VALUE
    }
    class TestEntry {
        public string Question { get; set; }
        public string Explanation { get; set; }
        public RandomList<string> Variants { get; set; }
        public string givenAnswer { get; set; }
        public string correctAnswer { get; set; }
        public TestType EntryType { get; set; }
        public bool isCorrect {
            get {
                if (correctAnswer.Equals(givenAnswer)) return true;
                return false;
            }
        }
        public TestEntry() {
           Variants = new RandomList<string>();
        }
        public void Load(StreamReader sr) {
            int Mode = 0;
            while (Mode != 9) {
                string Str = sr.ReadLine();
                if (Str == null||Str.Length==0) return;    //end of file reached
                switch (Str[0]) {
                    case '>': addQuestion(Str); break;
                    case '%': Explanation = Str.Substring(1); break;
                    case '$': Variants.Add(Str.Substring(1)); break;
                    case '#': Variants.Add(Str.Substring(1)); correctAnswer = Str.Substring(1); break;
                    default: Mode = 9;
                        break;
                }
            }
        }
        private void addQuestion(string Str) {
            if (Str[1] == '>') {
                EntryType = TestType.MISS_VALUE;
                Question = Str.Substring(2);
                return;
            }
            EntryType = TestType.VARIANTS;
            Question = Str.Substring(1);
        }
    }
}
